package com.mumu.coroutinenewdemo

import android.app.ActivityManager
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity

class LifeActivity : AppCompatActivity(), DeviceKeyMonitor.OnKeyListener {
    var group: ViewGroup? = null
    var imageView: ImageView? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_scrolling)
        group = window.decorView as ViewGroup

        DeviceKeyMonitor(this, this)
        Log.i(TAG, "onCreate: ")

//        ActivityManager.RecentTaskInfo
//        val am :ActivityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
//        TaskSnapshotController
    }

    override fun onRestart() {
        super.onRestart()
        Log.i(TAG, "onRestart: 2")
    }

    override fun onStart() {
        super.onStart()
        Log.i(TAG, "onStart: 2")
    }

    override fun onResume() {
        Log.i(TAG, "onResume: ")
        super.onResume()
        Log.i(TAG, "onResume: 2")
    }

    override fun onPause() {
        Log.d(TAG, "onPause: ")
        super.onPause()
        Log.d(TAG, "onPause: 2")
    }

    override fun onStop() {
        Log.d(TAG, "onStop: ")
        super.onStop()
        Log.d(TAG, "onStop: 2")
        onRecent()
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d(TAG, "onDestroy: 2")
    }

    companion object {
        private const val TAG = "lwz"
    }

    fun onRecent() {
        group?.removeView(imageView)
        imageView = ImageView(this)
        imageView?.scaleType = ImageView.ScaleType.FIT_XY
        val params = FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        imageView?.layoutParams = params

        val bitmap = PicUtil.rsBlur(this, PicUtil.activityShot(this), 20)
        imageView?.setImageBitmap(bitmap)
        group?.addView(imageView)
    }

    override fun onRecentClick() {

    }


}